﻿@model ShoppingCartModel
@using SmartStore.Core.Domain.Orders;
@using SmartStore.Web.Models.ShoppingCart;
<div class="order-summary-content">

    @Html.Widget("order_summary_content_before")
    @Html.Partial("_OrderReviewData", Model.OrderReviewData)

    @if (Model.Items.Count > 0)
    {
        if (Model.Warnings.Count > 0)
        {
        <div class="alert alert-error">
            @for (int i = 0; i < Model.Warnings.Count; i++)
            {
                <p>@Model.Warnings[i]</p>
            }
        </div>
        }
        @*we add enctype = "multipart/form-data" because "File upload" attribute control type requries it*@
        using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
        <table class="cart table table-striped">
            <thead>
                <tr class="cart-header-row">
                    @if (Model.IsEditable)
                    {
                        <th>
                            @T("ShoppingCart.Remove")
                        </th>
                    }
                    @if (Model.ShowSku)
                    {
                        <th>
                            @T("ShoppingCart.SKU")
                        </th>
                    }
                    @if (Model.ShowProductImages)
                    {
                        <th class="picture"></th>
                    }
                    <th>
                        @T("ShoppingCart.Product(s)")
                    </th>
                    <th class="unit-price">
                        @T("ShoppingCart.UnitPrice")
                    </th>
                    <th>
                        @T("ShoppingCart.Quantity")
                    </th>
                    <th class="omega">
                        @T("ShoppingCart.ItemTotal")
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Items)
                {
                    <tr class="cart-item-row">
                        @if (Model.IsEditable)
                        {
                            <td class="remove">
                                <input type="checkbox" name="removefromcart" value="@(item.Id)" />
                            </td>
                        }
                        @if (Model.ShowSku)
                        {
                            <td class="nobr">
                                @item.Sku
                            </td>
                        }
                        @if (Model.ShowProductImages)
                        {
                            <td class="productpicture nobr">
                                <img class="img-polaroid" alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" style="max-width:@(Model.MediaDimensions)px;max-height:@(Model.MediaDimensions)px"/>
                            </td>
                        }
                        <td class="product">
                            <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="View details">@item.ProductName</a>
                            @if (!String.IsNullOrEmpty(item.AttributeInfo))
                            {
                                <div class="attributes muted">
                                    @Html.Raw(item.AttributeInfo)
                                </div>
                            }
                            @if (!String.IsNullOrEmpty(item.RecurringInfo))
                            {
                                <div class="recurring-info">
                                    @Html.Raw(item.RecurringInfo)
                                </div>
                            }
                            @if (item.Warnings.Count > 0)
                            {
                                <div class="alert alert-error">
                                    @for (int i = 0; i < item.Warnings.Count; i++)
                                    {
                                        <p>@item.Warnings[i]</p>
                                    }
                                </div>
                            }
                        </td>
                        <td class="unit-price nobr">
                            <span class="product-unit-price">@item.UnitPrice</span>
                        </td>
                        <td class="nobr">
                            @if (Model.IsEditable)
                            {
                                if (item.AllowedQuantities.Count > 0)
                                {
                                <select name="itemquantity@(item.Id)" class="qty-dropdown noskin">
                                    @foreach (var qty in item.AllowedQuantities)
                                    {
                                        <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                    }
                                </select>
                                }
                                else
                                {
                                    <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="qty-input hide" />
                                }

                            }
                            else
                            {
                                <span>@item.Quantity</span>
                            }
                        </td>
                        <td class="nobr text-success omega">
                            <span class="product-subtotal">@item.SubTotal</span>
                            @if (!String.IsNullOrEmpty(item.Discount))
                            {
                                <div class="discount">
                                    @T("ShoppingCart.ItemYouSave"): @item.Discount
                                </div>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>

                if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
            <div class="selected-checkout-attributes well well-small" style="text-align: right">
                @Html.Raw(Model.CheckoutAttributeInfo)
            </div>
                }

                if (Model.IsEditable)
                {
            <div class="common-buttons clearfix">
                <button type="submit" name="continueshopping" value="continueshopping" class="btn pull-left continue-shopping-button">
                    <i class="icon-caret-left"></i>&nbsp;
                    @T("ShoppingCart.ContinueShopping")
                </button>
                <button type="submit" name="updatecart" value="updatecart" class="btn pull-right update-cart-button">
                    <i class="icon-refresh"></i>&nbsp;
                    @T("ShoppingCart.UpdateCart")
                </button>
                <input type="submit" name="startcheckout" value="startcheckout" id="startcheckout" style="display: none;" />
            </div>
                }
        
        <div class="cart-footer row-fluid">

            <!-- Discount Code, Gift Cards, Estimate shipping -->
            <div class="span8">
                @if (Model.IsEditable)
                {
                    @Html.Partial("_DiscountBox", Model.DiscountBox)
                    @Html.Partial("_GiftCardBox", Model.GiftCardBox)
                    @Html.Widget("order_summary_content_deals")
                }
            </div>

            <!-- Checkout attributes -->
            <div class="span8">
                @if (Model.IsEditable)
                {
                    @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
                    @Html.Partial("EstimateShipping", Model.EstimateShipping)
                }
            </div>

            <!-- Totals -->
            <div class="span8">

                @if (Model.IsEditable && !String.IsNullOrEmpty(Model.MinOrderSubtotalWarning)) 
                {
                    <div class="alert alert-info" style="margin-top: 0">
                        @Model.MinOrderSubtotalWarning
                    </div>
                }

                @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })

                @if (Model.IsEditable)
                {
                    
                    <div class="checkout-buttons">
                        @if (String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                        {
                            <button type="button" 
                                    class="btn btn-primary btn-large pull-right checkout-button" 
                                    id="checkout" 
                                    name="checkout"
                                    onclick="$('#startcheckout').trigger('click'); return false;">
                                @T("Checkout.Button")&nbsp;
                                <i class="icon-arrow-right" style="font-size: 18px"></i>
                            </button>
                        }
                    </div>
                    
                    <div class="addon-buttons">
                        @*Payment method buttons (e.g. GoogleCheckoutButton, Paypal Express)*@
                        @Html.Partial("_ButtonPaymentMethod", Model)
                    </div>
                }

            </div>

        </div>
        
        }
        
        @Html.Widget("order_summary_content_after")

        if (Model.IsEditable)
        {
            @Html.Action("CrossSellProducts", "Catalog")
        }
    }
    else
    {
        @T("ShoppingCart.CartIsEmpty")
    }

</div>
